<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上级排产编号" prop="parentProductionNumber">
        <el-input
          v-model="queryParams.parentProductionNumber"
          placeholder="请输入上级排产编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="排产编号" prop="pcId">
        <el-input
          v-model="queryParams.pcId"
          placeholder="请输入排产编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产线名称" prop="lineName">
        <el-input
          v-model="queryParams.lineName"
          placeholder="请输入生产线名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工位名称" prop="gwName">
        <el-input
          v-model="queryParams.gwName"
          placeholder="请输入工位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备编号" prop="sbbh">
        <el-input
          v-model="queryParams.sbbh"
          placeholder="请输入设备编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="员工工号" prop="workNum">
        <el-input
          v-model="queryParams.workNum"
          placeholder="请输入员工工号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['sales:ncProcessingFormalSchedulingPlan:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['sales:ncProcessingFormalSchedulingPlan:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['sales:ncProcessingFormalSchedulingPlan:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['sales:ncProcessingFormalSchedulingPlan:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="info"
            plain
            icon="el-icon-upload2"
            size="mini"
            @click="handleImport"
        >导入</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ncProcessingFormalSchedulingPlanList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="公司代码" align="center" prop="factoryCode" />
      <el-table-column label="公司名称" align="center" prop="factoryName" />
      <el-table-column label="订单号" align="center" prop="orderNo" />
<!--      <el-table-column label="订单类型" align="center" prop="orderType" width="140">-->
<!--        <template slot-scope="scope">-->
<!--          <span v-if="scope.row.orderType=='1'">正式</span>-->
<!--          <span v-if="scope.row.orderType=='2'">预测</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="成品编号" align="center" prop="productNumber" />
      <el-table-column label="成品名称" align="center" prop="productName" />
      <el-table-column label="总成编号" align="center" prop="zcCode" />
      <el-table-column label="总成名称" align="center" prop="zcName" />
      <el-table-column label="部件编号" align="center" prop="partNumber" />
      <el-table-column label="部件名称" align="center" prop="partName" />
      <el-table-column label="上级排产编号" align="center" prop="parentProductionNumber" />
      <el-table-column label="合同号" align="center" prop="contract" />
      <el-table-column label="排产编号" align="center" prop="pcId" />
      <el-table-column label="排产日期" align="center" prop="pcDate" width="180"/>
      <el-table-column label="生产日期" align="center" prop="productionTime" width="180"/>
      <el-table-column label="交货日期" align="center" prop="jhDate" width="180"/>
      <el-table-column label="生产线代码" align="center" prop="lineId" />
      <el-table-column label="生产线名称" align="center" prop="lineName" />
      <el-table-column label="工位代码" align="center" prop="gwCode" />
      <el-table-column label="工位名称" align="center" prop="gwName" />
      <el-table-column label="工位物料编码" align="center" prop="gwItemCode" />
      <el-table-column label="工位物料名称" align="center" prop="gwItemName" />
      <el-table-column label="单位" align="center" prop="unit" />
      <el-table-column label="单台用量" align="center" prop="dtyl" />
      <el-table-column label="订单用量" align="center" prop="ddyl" />
      <el-table-column label="设备编号" align="center" prop="sbbh" />
      <el-table-column label="设备名称" align="center" prop="deviceName" />
      <el-table-column label="员工工号" align="center" prop="workNum" />
      <el-table-column label="员工姓名" align="center" prop="employeeName" />
      <el-table-column label="产品类型" align="center" prop="proType" />
      <el-table-column label="工序产品编号" align="center" prop="gxProCode" />
      <el-table-column label="产品名称" align="center" prop="itemName" />
      <el-table-column label="对应产品编号" align="center" prop="dyProCode" />
      <el-table-column label="对应原材料编号" align="center" prop="dyYclCode" />
      <el-table-column label="对应整车图号" align="center" prop="dyZcNum" />
      <el-table-column label="订单数量" align="center" prop="orderNum" />
      <el-table-column label="未排产订单数量" align="center" prop="noPcNum" />
      <el-table-column label="排产数量" align="center" prop="pcNum" />
      <el-table-column label="实际完成数量" align="center" prop="finishComNum" />
      <el-table-column label="在制品数量" align="center" prop="zzNum" />
      <el-table-column label="检验数量" align="center" prop="checkNum" />
      <el-table-column label="不合格数量" align="center" prop="bhgNum" />
      <el-table-column label="返修数量" align="center" prop="returnNum" />
      <el-table-column label="料废数量" align="center" prop="flNum" />
      <el-table-column label="机废数量" align="center" prop="jfNum" />
      <el-table-column label="计划上线时间" align="center" prop="planOnlineTime" width="180"/>
      <el-table-column label="实际上线时间" align="center" prop="actualOnlineTime" width="180"/>
      <el-table-column label="计划下线时间" align="center" prop="planOfflineTime" width="180"/>
      <el-table-column label="实际下线时间" align="center" prop="actualOfflineTime" width="180"/>
      <el-table-column label="返修上线时间" align="center" prop="returnOnlineTime" width="180"/>
      <el-table-column label="返修下线时间" align="center" prop="returnOfflineTime" width="180"/>
      <el-table-column label="检验时间" align="center" prop="checkTime" width="180"/>
      <el-table-column label="质检员工号" align="center" prop="zjyNo" />
      <el-table-column label="质检员姓名" align="center" prop="zjyName" />
      <el-table-column label="包装时间" align="center" prop="packgeTime" width="180"/>
      <el-table-column label="核销时间" align="center" prop="hxTime" width="180"/>
      <el-table-column label="备注" align="center" prop="remark" />


      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['sales:ncProcessingFormalSchedulingPlan:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['sales:ncProcessingFormalSchedulingPlan:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改零件排产计划对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="公司代码" prop="factoryCode">
              <el-input v-model="form.factoryCode" placeholder="请输入公司代码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公司名称" prop="factoryName">
              <el-input v-model="form.factoryName" placeholder="请输入公司名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="订单号" prop="orderNo">
              <el-input v-model="form.orderNo" placeholder="请输入订单号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="上级排产编号" prop="parentProductionNumber">
              <el-input v-model="form.parentProductionNumber" placeholder="请输入上级排产编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="选择" prop="choose">
              <el-input v-model="form.choose" placeholder="请输入选择" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合同号" prop="contract">
              <el-input v-model="form.contract" placeholder="请输入合同号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="排产编号" prop="pcId">
              <el-input v-model="form.pcId" placeholder="请输入排产编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="排产日期" prop="pcDate">
              <el-date-picker clearable
                v-model="form.pcDate"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择排产日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生产日期" prop="productionTime">
              <el-date-picker clearable
                v-model="form.productionTime"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择生产日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="交货日期" prop="jhDate">
              <el-date-picker clearable
                v-model="form.jhDate"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择交货日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生产线代码" prop="lineId">
              <el-input v-model="form.lineId" placeholder="请输入生产线代码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生产线名称" prop="lineName">
              <el-input v-model="form.lineName" placeholder="请输入生产线名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工位代码" prop="gwCode">
              <el-input v-model="form.gwCode" placeholder="请输入工位代码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工位名称" prop="gwName">
              <el-input v-model="form.gwName" placeholder="请输入工位名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备编号" prop="sbbh">
              <el-input v-model="form.sbbh" placeholder="请输入设备编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备名称" prop="deviceName">
              <el-input v-model="form.deviceName" placeholder="请输入设备名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="员工工号" prop="workNum">
              <el-input v-model="form.workNum" placeholder="请输入员工工号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="员工姓名" prop="employeeName">
              <el-input v-model="form.employeeName" placeholder="请输入员工姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工序产品编号" prop="gxProCode">
              <el-input v-model="form.gxProCode" placeholder="请输入工序产品编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="产品名称" prop="itemName">
              <el-input v-model="form.itemName" placeholder="请输入产品名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="对应产品编号" prop="dyProCode">
              <el-input v-model="form.dyProCode" placeholder="请输入对应产品编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="对应原材料编号" prop="dyYclCode">
              <el-input v-model="form.dyYclCode" placeholder="请输入对应原材料编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="对应整车图号" prop="dyZcNum">
              <el-input v-model="form.dyZcNum" placeholder="请输入对应整车图号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="订单数量" prop="orderNum">
              <el-input v-model="form.orderNum" placeholder="请输入订单数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="未排产订单数量" prop="noPcNum">
              <el-input v-model="form.noPcNum" placeholder="请输入未排产订单数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="排产数量" prop="pcNum">
              <el-input v-model="form.pcNum" placeholder="请输入排产数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="实际完成数量" prop="finishComNum">
              <el-input v-model="form.finishComNum" placeholder="请输入实际完成数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="在制品数量" prop="zzNum">
              <el-input v-model="form.zzNum" placeholder="请输入在制品数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检验数量" prop="checkNum">
              <el-input v-model="form.checkNum" placeholder="请输入检验数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="不合格数量" prop="bhgNum">
              <el-input v-model="form.bhgNum" placeholder="请输入不合格数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="返修数量" prop="returnNum">
              <el-input v-model="form.returnNum" placeholder="请输入返修数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="料废数量" prop="flNum">
              <el-input v-model="form.flNum" placeholder="请输入料废数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="机废数量" prop="jfNum">
              <el-input v-model="form.jfNum" placeholder="请输入机废数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计划上线时间" prop="planOnlineTime">
              <el-date-picker clearable
                v-model="form.planOnlineTime"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择计划上线时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="实际上线时间" prop="actualOnlineTime">
              <el-date-picker clearable
                v-model="form.actualOnlineTime"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择实际上线时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计划下线时间" prop="planOfflineTime">
              <el-date-picker clearable
                v-model="form.planOfflineTime"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择计划下线时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="实际下线时间" prop="actualOfflineTime">
              <el-date-picker clearable
                v-model="form.actualOfflineTime"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择实际下线时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="返修上线时间" prop="returnOnlineTime">
              <el-date-picker clearable
                v-model="form.returnOnlineTime"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择返修上线时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="返修下线时间" prop="returnOfflineTime">
              <el-date-picker clearable
                v-model="form.returnOfflineTime"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择返修下线时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检验时间" prop="checkTime">
              <el-date-picker clearable
                v-model="form.checkTime"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择检验时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="质检员工号" prop="zjyNo">
              <el-input v-model="form.zjyNo" placeholder="请输入质检员工号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="质检员姓名" prop="zjyName">
              <el-input v-model="form.zjyName" placeholder="请输入质检员姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="包装时间" prop="packgeTime">
              <el-date-picker clearable
                v-model="form.packgeTime"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择包装时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="核销时间" prop="hxTime">
              <el-date-picker clearable
                v-model="form.hxTime"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择核销时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工位物料编码" prop="gwItemCode">
              <el-input v-model="form.gwItemCode" placeholder="请输入工位物料编码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工位物料名称" prop="gwItemName">
              <el-input v-model="form.gwItemName" placeholder="请输入工位物料名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位" prop="unit">
              <el-input v-model="form.unit" placeholder="请输入单位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单台用量" prop="dtyl">
              <el-input v-model="form.dtyl" placeholder="请输入单台用量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="订单用量" prop="ddyl">
              <el-input v-model="form.ddyl" placeholder="请输入订单用量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="成品编号" prop="productNumber">
              <el-input v-model="form.productNumber" placeholder="请输入成品编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="成品名称" prop="productName">
              <el-input v-model="form.productName" placeholder="请输入成品名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="总成编号" prop="zcCode">
              <el-input v-model="form.zcCode" placeholder="请输入总成编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="总成名称" prop="zcName">
              <el-input v-model="form.zcName" placeholder="请输入总成名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="部件编号" prop="partNumber">
              <el-input v-model="form.partNumber" placeholder="请输入部件编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="部件名称" prop="partName">
              <el-input v-model="form.partName" placeholder="请输入部件名称" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
          ref="upload"
          :limit="1"
          accept=".xlsx, .xls"
          :headers="upload.headers"
          :action="upload.url + '?updateSupport=' + upload.updateSupport"
          :disabled="upload.isUploading"
          :on-progress="handleFileUploadProgress"
          :on-success="handleFileSuccess"
          :auto-upload="false"
          drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <!--  <div class="el-upload__tip" slot="tip">
              <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
            </div>-->
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listNcProcessingFormalSchedulingPlan, getNcProcessingFormalSchedulingPlan, delNcProcessingFormalSchedulingPlan, addNcProcessingFormalSchedulingPlan, updateNcProcessingFormalSchedulingPlan } from "@/api/sales/ncProcessingFormalSchedulingPlan";
import {getToken} from "@/utils/auth";
export default {
  name: "NcProcessingFormalSchedulingPlan",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 零件排产计划表格数据
      ncProcessingFormalSchedulingPlanList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: null,
        orderType: null,
        parentProductionNumber: null,
        contract: null,
        pcId: null,
        lineName: null,
        gwName: null,
        sbbh: null,
        deviceName: null,
        workNum: null,
        proType: null,
        gxProCode: null,
        itemName: null,
        dyProCode: null,
        dyYclCode: null,
        dyZcNum: null,
        zjyNo: null,
        gwItemName: null,
        productNumber: null,
        productName: null,
        zcCode: null,
        zcName: null,
        partNumber: null,
        partName: null
      },
      upload: {
        // 是否显示弹出层
        open: false,
        // 弹出层标题
        title: "导入`ncProcessingFormalSchedulingPlan`信息",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/sales/ncProcessingFormalSchedulingPlan/importData"
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询零件排产计划列表 */
    getList() {
      this.loading = true;
      listNcProcessingFormalSchedulingPlan(this.queryParams).then(response => {
        this.ncProcessingFormalSchedulingPlanList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        factoryCode: null,
        factoryName: null,
        orderNo: null,
        orderType: null,
        parentProductionNumber: null,
        choose: null,
        contract: null,
        pcId: null,
        pcDate: null,
        productionTime: null,
        jhDate: null,
        lineId: null,
        lineName: null,
        gwCode: null,
        gwName: null,
        sbbh: null,
        deviceName: null,
        workNum: null,
        employeeName: null,
        proType: null,
        gxProCode: null,
        itemName: null,
        dyProCode: null,
        dyYclCode: null,
        dyZcNum: null,
        orderNum: null,
        noPcNum: null,
        pcNum: null,
        finishComNum: null,
        zzNum: null,
        checkNum: null,
        bhgNum: null,
        returnNum: null,
        flNum: null,
        jfNum: null,
        planOnlineTime: null,
        actualOnlineTime: null,
        planOfflineTime: null,
        actualOfflineTime: null,
        returnOnlineTime: null,
        returnOfflineTime: null,
        checkTime: null,
        zjyNo: null,
        zjyName: null,
        packgeTime: null,
        hxTime: null,
        remark: null,
        gwItemCode: null,
        gwItemName: null,
        unit: null,
        dtyl: null,
        ddyl: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        productNumber: null,
        productName: null,
        zcCode: null,
        zcName: null,
        partNumber: null,
        partName: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加零件排产计划";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getNcProcessingFormalSchedulingPlan(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改零件排产计划";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateNcProcessingFormalSchedulingPlan(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addNcProcessingFormalSchedulingPlan(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除数据？').then(function() {
        return delNcProcessingFormalSchedulingPlan(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('sales/ncProcessingFormalSchedulingPlan/export', {
        ...this.queryParams
      }, `ncProcessingFormalSchedulingPlan_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "零件排产计划导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('sales/ncProcessingFormalSchedulingPlan/importTemplate', {
      }, `零件排产计划模板.xlsx`)
    },
    /** 文件上传中处理 */
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    /** 文件上传成功处理 */
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    /** 提交上传文件 */
    submitFileForm() {
      this.$refs.upload.submit();
    },
  }
};
</script>
